package 力扣日常刷题.木23一月.第01天301;

/**
 * @author 帅小伙
 * @date 2022/3/1
 * @description
 */
public class Demo02二维数组中的查找 {


    public boolean find(int[][] matrix,int target){
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int x = matrix.length,y = matrix[0].length;
        int curX = 0,curY = y - 1;
        while(curX < x && curY >=0){
            if(matrix[curX][curY] == target) return true;
            else if(matrix[curX][curY] > target) curY --;
            else curX++;
        }
        return false;
    }
}
